supernova: fixes for boost-1.49 and gcc-4.7
[supercollider.git] / Help / Other Topics / play.html
blob91ddf676ccbf15129c29f06abdba0303ce1f5148
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.43">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0025b2}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0000ff}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
21 p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #982316}
22 span.s1 {color: #0025b2}
23 span.s2 {color: #606060}
24 span.s3 {color: #000000}
25 span.s4 {font: 9.0px Monaco}
26 span.s5 {color: #416d1f}
27 span.s6 {color: #0000ff}
28 span.s7 {font: 12.0px Helvetica}
29 span.s8 {color: #0000bf}
30 span.s9 {color: #007300}
31 span.s10 {color: #bf0000}
32 span.Apple-tab-span {white-space:pre}
33 </style>
34 </head>
35 <body>
36 <p class="p1"><b>play</b></p>
37 <p class="p2"><br></p>
38 <p class="p2"><br></p>
39 <p class="p3"><b>start a process</b></p>
40 <p class="p4"><br></p>
41 <p class="p4"><br></p>
42 <p class="p3">this message is of common use in sc. Different objects respond to it in various</p>
43 <p class="p3">ways, but the simple meaning is: start a process.</p>
44 <p class="p3">It is usually implemented by objects in contributed libraries as well.</p>
45 <p class="p4"><br></p>
46 <p class="p3">play usually returns the playing object which might not be the same as the one</p>
47 <p class="p3">the message was sent to.</p>
48 <p class="p4"><br></p>
49 <p class="p3">opposite: <b>stop</b></p>
50 <p class="p2"><br></p>
51 <p class="p2"><br></p>
52 <p class="p2"><br></p>
53 <p class="p3"><b>clock.play(stream)</b></p>
54 <p class="p3">returns: the clock</p>
55 <p class="p2"><span class="Apple-tab-span"> </span></p>
56 <p class="p5"><span class="Apple-tab-span"> </span>(</p>
57 <p class="p5"><span class="Apple-tab-span"> </span>r = <span class="s1">Routine</span>.new({ <span class="s2">"...playing"</span>.postln; 1.wait; <span class="s2">"ok, that was it"</span>.postln });</p>
58 <p class="p6"><span class="s3"><span class="Apple-tab-span"> </span></span>SystemClock<span class="s3">.play(r);</span></p>
59 <p class="p5"><span class="Apple-tab-span"> </span>)</p>
60 <p class="p2"><br></p>
61 <p class="p3"><b>routine.play(clock)</b></p>
62 <p class="p3">returns: the routine</p>
63 <p class="p2"><br></p>
64 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">Routine</span>.new({ <span class="s2">"...playing"</span>.postln; 1.wait; <span class="s2">"ok, that was it"</span>.postln }).play;</p>
65 <p class="p2"><br></p>
66 <p class="p2"><br></p>
67 <p class="p3"><b>stream.play(clock)</b></p>
68 <p class="p3">returns the stream</p>
69 <p class="p3"><span class="s4"><span class="Apple-tab-span"> </span></span>the stream will loop until it returns nil</p>
70 <p class="p4"><span class="Apple-tab-span"> </span></p>
71 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">FuncStream</span>({ <span class="s2">"ok, that was it"</span>.postln; 1 }).play;</p>
72 <p class="p2"><span class="Apple-tab-span"> </span></p>
73 <p class="p2"><span class="Apple-tab-span"> </span></p>
74 <p class="p3"><b>pausestream.play(clock) / task.play(clock)</b></p>
75 <p class="p3">returns the stream</p>
76 <p class="p2"><br></p>
77 <p class="p5"><span class="Apple-tab-span"> </span>a = <span class="s1">PauseStream</span>.new(<span class="s1">FuncStream</span>.new({ <span class="s2">"ok, that was it"</span>.postln; 1 }));</p>
78 <p class="p5"><span class="Apple-tab-span"> </span>a.play;</p>
79 <p class="p5"><span class="Apple-tab-span"> </span>a.stop;</p>
80 <p class="p5"><span class="Apple-tab-span"> </span>a.play;</p>
81 <p class="p5"><span class="Apple-tab-span"> </span>a.stop;</p>
82 <p class="p2"><span class="Apple-tab-span"> </span></p>
83 <p class="p5"><span class="Apple-tab-span"> </span>a = <span class="s1">Task</span>.new({ loop({ <span class="s2">"ok, that was it"</span>.postln; 1.wait; }) });</p>
84 <p class="p5"><span class="Apple-tab-span"> </span>a.play;</p>
85 <p class="p5"><span class="Apple-tab-span"> </span>a.stop;</p>
86 <p class="p2"><span class="Apple-tab-span"> </span></p>
87 <p class="p2"><span class="Apple-tab-span"> </span></p>
88 <p class="p3"><b>pattern.play(clock, protoEvent)</b></p>
89 <p class="p3">returns: an <b>EventStreamPlayer</b></p>
90 <p class="p2"><br></p>
91 <p class="p5"><span class="Apple-tab-span"> </span>(</p>
92 <p class="p6"><span class="s3"><span class="Apple-tab-span"> </span></span>Pseq<span class="s3">([</span></p>
93 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pbind</span>(<span class="s5">\freq</span>, <span class="s1">Pn</span>(500, 1)),</p>
94 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s1">Pbind</span>(<span class="s5">\dur</span>, <span class="s1">Pn</span>(0.1, 1))</p>
95 <p class="p5"><span class="Apple-tab-span"> </span>], 2).play;</p>
96 <p class="p5"><span class="Apple-tab-span"> </span>)</p>
97 <p class="p2"><br></p>
98 <p class="p2"><br></p>
99 <p class="p2"><br></p>
100 <p class="p2"><br></p>
101 <p class="p2"><br></p>
102 <p class="p7"><b>Playing single Synths from SynthDefs on the server</b></p>
103 <p class="p4"><br></p>
104 <p class="p2"><br></p>
105 <p class="p3">The following play messages both cause a <a href="../ServerArchitecture/SynthDef.html"><span class="s6">SynthDef</span></a> to be written, send it to the server<span class="Apple-converted-space"> </span></p>
106 <p class="p3">and start a synth with it there.</p>
107 <p class="p4"><br></p>
108 <p class="p3">Note that they should not be used in quickly running automated processes,</p>
109 <p class="p3">as there are more efficient alternatives (see <a href="../3vs2/SynthDefsVsSynths.html"><span class="s6">SynthDefsVsSynths</span></a><b>)</b></p>
110 <p class="p4"><br></p>
111 <p class="p2"><br></p>
112 <p class="p2"><br></p>
113 <p class="p3"><b>function.play(target, outbus, fadeTime, addAction, args)</b></p>
114 <p class="p4"><br></p>
115 <p class="p8"><span class="s3">See <a href="../Core/Kernel/Function.html"><span class="s7">Function</span></a></span></p>
116 <p class="p3">returns: a <a href="../ServerArchitecture/Synth.html"><span class="s6">Synth</span></a></p>
117 <p class="p2"><span class="Apple-tab-span"> </span></p>
118 <p class="p3"><span class="s4"><span class="Apple-tab-span"> </span></span><b>outbus</b>: on what bus to play (default: 0)</p>
119 <p class="p3"><span class="Apple-tab-span"> </span><b>fadeTime</b>: in what time to fade out when released (defaulr: 0.02)</p>
120 <p class="p3"><span class="Apple-tab-span"> </span><b>addAction</b>: where to add the node (\addToHead by default)</p>
121 <p class="p3"><span class="Apple-tab-span"> </span><b>args</b>: controls to set when starting the synth</p>
122 <p class="p2"><br></p>
123 <p class="p2"><br></p>
124 <p class="p9">a = { <span class="s8">PinkNoise</span>.ar([0.1, 0.1]) }.play;</p>
125 <p class="p9">a.release;</p>
126 <p class="p10"><br></p>
127 <p class="p11">// setting argument</p>
128 <p class="p9">a = { <span class="s8">|freq = 500|</span> <span class="s8">HPF</span>.ar(<span class="s8">PinkNoise</span>.ar([1, 1] * 0.4), freq) }.play;</p>
129 <p class="p9">a.set(<span class="s9">\freq</span>, 1000)</p>
130 <p class="p9">a.release;</p>
131 <p class="p10"><br></p>
132 <p class="p11">// passing argument with play:</p>
133 <p class="p9">a = { <span class="s8">|freq = 500|</span> <span class="s8">HPF</span>.ar(<span class="s8">PinkNoise</span>.ar([1, 1] * 0.4), freq) }.play(args: [<span class="s9">\freq</span>, 10000]);</p>
134 <p class="p10"><br></p>
135 <p class="p10"><br></p>
136 <p class="p11">// note that you can use Out ugens but you do not need to</p>
137 <p class="p9">{ <span class="s8">Out</span>.ar(1, <span class="s8">PinkNoise</span>.ar(0.1)) }.play;</p>
138 <p class="p9">{ <span class="s8">XOut</span>.ar(0, <span class="s8">MouseX</span>.kr(0,1), <span class="s8">PinkNoise</span>.ar(0.1*[1,1])) }.play; <span class="s10">// mouse x controls level</span></p>
139 <p class="p4"><br></p>
140 <p class="p4"><br></p>
141 <p class="p4"><br></p>
142 <p class="p2"><br></p>
143 <p class="p3"><b>synthDef.play(target, args, addAction)</b></p>
144 <p class="p3">returns: a <b>Synth</b></p>
145 <p class="p4"><span class="Apple-tab-span"> </span></p>
146 <p class="p3"><span class="Apple-tab-span"> </span>Note that you need an <b>out ugen</b> to hear the result.</p>
147 <p class="p3"><span class="Apple-tab-span"> </span>Examples of how to write to the busses in the helpfiles: <a href="../UGens/InOut/Out.html"><span class="s6">Out</span></a> / <a href="../UGens/InOut/ReplaceOut.html"><span class="s6">ReplaceOut</span></a> / <a href="../UGens/InOut/XOut.html"><span class="s6">XOut</span></a> / <a href="../UGens/InOut/OffsetOut.html"><span class="s6">OffsetOut</span></a></p>
148 <p class="p4"><span class="Apple-tab-span"> </span></p>
149 <p class="p3"><span class="Apple-tab-span"> </span>Nevertheless, synths can also run without any writing activity: (see e.g. <a href="../UGens/Triggers/SendTrig.html"><span class="s6">SendTrig</span></a><b>)</b></p>
150 <p class="p4"><span class="Apple-tab-span"> </span></p>
151 <p class="p3"><span class="Apple-tab-span"> </span>Some operations provide an out ugen <b>internally</b>: see for example <b>function.play</b>, which plays out</p>
152 <p class="p3"><span class="Apple-tab-span"> </span>to a bus number provided in the argument passed to .play</p>
153 <p class="p2"><br></p>
154 <p class="p2"><br></p>
155 <p class="p5">(</p>
156 <p class="p5"><span class="s1">x = SynthDef</span>(<span class="s2">"test"</span>, { arg out, amp=0.1;</p>
157 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">var</span> sound;</p>
158 <p class="p5"><span class="Apple-tab-span"> </span>sound = <span class="s1">PinkNoise</span>.ar(amp * [1,1]);</p>
159 <p class="p5"><span class="Apple-tab-span"> </span><span class="s1">Out</span>.ar(out, sound);</p>
160 <p class="p5">}).play;</p>
161 <p class="p5">)</p>
162 <p class="p2"><br></p>
163 <p class="p12">//set the synth</p>
164 <p class="p5">x.set(<span class="s5">\amp</span>, 0.2);</p>
165 <p class="p12">//free the synth</p>
166 <p class="p5">x.free;</p>
167 <p class="p2"><br></p>
168 <p class="p2"><br></p>
169 <p class="p3"><b>note</b>: Synth.play(function), is synonymous. for backwards compatibility with sc2</p>
170 <p class="p4"><br></p>
171 <p class="p2"><br></p>
172 <p class="p2"><br></p>
173 <p class="p2"><br></p>
174 <p class="p2"><br></p>
175 <p class="p2"><br></p>
176 <p class="p2"><span class="Apple-tab-span"> </span></p>
177 </body>
178 </html>